<?php
Class Module_Admin_Form_User extends Engine_Form {

    public function init(){


        $element = new Engine_Form_Element_Select('role');
        $element->setLabel('Роль');
        $this->addElement($element);

        $element = new Engine_Form_Element_Input('firstname');
        $element->setLabel('Имя');
        $element->setRequire(true);
        $this->addElement($element);

        $element = new Engine_Form_Element_Input('lastname');
        $element->setLabel('Фамилия');
        $element->setRequire(true);
        $this->addElement($element);

        $element = new Engine_Form_Element_Input('login');
        $element->setLabel('Логин');
        $element->addValidator(new Engine_Form_Validator_Length(5));
        $element->setRequire(true);
        $this->addElement($element);

        $element = new Engine_Form_Element_Password('password');
        $element->setLabel('Пароль');
        $element->addValidator(new Engine_Form_Validator_Length(8));
        $element->setRequire(true);
        $this->addElement($element);

        $element = new Engine_Form_Element_Password('accept_password');
        $element->setLabel('Подтверждение пароля');
        $element->addValidator(new Engine_Form_Validator_Length(8));
        $element->setRequire(true);
        $this->addElement($element);

        $element = new Engine_Form_Element_Submit('submit');
        $element->setLabel('Сохранить');
        $this->addElement($element);
    }

    public function isValid(){
        $result = parent::isValid();
        $params = $this->getValues();
        if (isset($params['password']) && isset($params['accept_password']) && $params['password']!= $params['accept_password']){
            $this->getElement('password')->addError('Пароли должны совпадать');
            $this->getElement('accept_password')->addError('Пароли должны совпадать');
            $result = false;
        }
        return $result;
    }


}